package com.mjlf.ticket.robort;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName RobotLock
 * @auther mjlf
 * @Date 2019/6/18 19:05
 * @Description TODO
 */
public class RobotLock implements Runnable {
    private int num = 0;
    private int max = 50;

    @Override
    public void run() {
        synchronized (this) {
            while (num < max) {
                try {
                    TimeUnit.MICROSECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " get : " + (num++));
            }
        }
    }

    public static void main(String[] args) {
        RobotLock robotSyn = new RobotLock();
        for (int i = 0; i < 4; i++) {
            new Thread(robotSyn).start();
        }
    }
}
